From: Akseli Lahtinen Date: Wed, 7 May 2025 13:35:19 +0000 (+0300) Subject: [PATCH] KFileWidget: Fix key navigation escaping in save dialogs X-Git-Tag: archive/raspbian/6.13.0-6+rpi1^2~4 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22%22/%22http:/www.example.com/cgi/%22https:/%22%22?a=commitdiff_plain;h=feba3c5652722ee319d936966e0d16d553b64819;p=kf6-kio.git [PATCH] KFileWidget: Fix key navigation escaping in save dialogs In save dialogs the keyboard navigation would escape during file highlighting, since the fileHighlight sets the focus for fileName bar for mouse operations. This makes sure the user has to press Tab to explicitly escape the keyboard navigation mode. For clicking the items, it should not affect at all. CCBUG: 466206 FIXED-IN: 6.14 (cherry picked from commit 8e4e84f045b7459c0b02b1b1b51a9df73cea068a) Gbp-Pq: Name upstream_719e0b00_KFileWidget-Fix-key-navigation-escaping-in-save-dialogs.patch --- diff --git a/src/filewidgets/kdiroperator.cpp b/src/filewidgets/kdiroperator.cpp index e1d3afe..4a2e400 100644 --- a/src/filewidgets/kdiroperator.cpp +++ b/src/filewidgets/kdiroperator.cpp @@ -221,6 +221,7 @@ public: bool m_showOpenWithActions = false; bool m_isTouchEvent = false; bool m_isTouchDrag = false; + bool m_keyNavigation = false; QList m_itemsToBeSetAsCurrent; QStringList m_supportedSchemes; @@ -1244,6 +1245,11 @@ void KDirOperator::showOpenWithActions(bool enable) d->m_showOpenWithActions = enable; } +bool KDirOperator::usingKeyNavigation() +{ + return d->m_keyNavigation; +} + void KDirOperator::changeEvent(QEvent *event) { QWidget::changeEvent(event); @@ -1429,6 +1435,19 @@ bool KDirOperator::eventFilter(QObject *watched, QEvent *event) return true; } } + // Only use tab key to escape the view navigation + if (evt->key() == Qt::Key_Tab) { + d->m_keyNavigation = false; + d->slotSelectionChanged(); + // When saving we need to return here, + // otherwise we skip over the next item with our tab press + // since we focus on that item in slotSelectionChanged + if (d->m_isSaving) { + return true; + } + } else { + d->m_keyNavigation = true; + } break; } case QEvent::Resize: { @@ -1833,6 +1852,7 @@ void KDirOperator::selectFile(const KFileItem &item) QApplication::restoreOverrideCursor(); Q_EMIT fileSelected(item); + d->m_keyNavigation = false; } void KDirOperator::highlightFile(const KFileItem &item) @@ -1842,6 +1862,7 @@ void KDirOperator::highlightFile(const KFileItem &item) } Q_EMIT fileHighlighted(item); + d->m_keyNavigation = false; } void KDirOperator::setCurrentItem(const QUrl &url) diff --git a/src/filewidgets/kdiroperator.h b/src/filewidgets/kdiroperator.h index c348805..71a20ed 100644 --- a/src/filewidgets/kdiroperator.h +++ b/src/filewidgets/kdiroperator.h @@ -744,6 +744,13 @@ public: */ void showOpenWithActions(bool enable); + /*! + * @returns true if the user was using keys to navigate. + * + * \since 6.14 + */ + bool usingKeyNavigation(); + protected: /** * A view factory for creating predefined fileviews. Called internally by setView, diff --git a/src/filewidgets/kfilewidget.cpp b/src/filewidgets/kfilewidget.cpp index 37f5e87..8170f32 100644 --- a/src/filewidgets/kfilewidget.cpp +++ b/src/filewidgets/kfilewidget.cpp @@ -166,7 +166,7 @@ public: void enterUrl(const QString &); void locationAccepted(const QString &); void slotFilterChanged(); - void fileHighlighted(const KFileItem &); + void fileHighlighted(const KFileItem &, bool); void fileSelected(const KFileItem &); void slotLoadingFinished(); void togglePlacesPanel(bool show, QObject *sender = nullptr); @@ -908,7 +908,7 @@ void KFileWidget::accept() d->m_ops->close(); } -void KFileWidgetPrivate::fileHighlighted(const KFileItem &i) +void KFileWidgetPrivate::fileHighlighted(const KFileItem &i, bool isKeyNavigation) { if ((m_locationEdit->hasFocus() && !m_locationEdit->currentText().isEmpty())) { // don't disturb return; @@ -951,7 +951,7 @@ void KFileWidgetPrivate::fileHighlighted(const KFileItem &i) // rename it if desired // Note that double-clicking will override this and overwrite regardless of // single/double click mouse setting (see slotViewDoubleClicked() ) - if (m_operationMode == KFileWidget::Saving) { + if (!isKeyNavigation && m_operationMode == KFileWidget::Saving) { m_locationEdit->setFocus(); } } @@ -1106,7 +1106,7 @@ void KFileWidgetPrivate::initDirOpWidgets() urlEntered(url); }); q->connect(m_ops, &KDirOperator::fileHighlighted, q, [this](const KFileItem &item) { - fileHighlighted(item); + fileHighlighted(item, m_ops->usingKeyNavigation()); }); q->connect(m_ops, &KDirOperator::fileSelected, q, [this](const KFileItem &item) { fileSelected(item);